<?php
/**
 * Template Name: My Venue Slots
 */

get_header(); ?>

<div class="container">
    <h1><?php the_title() ?></h1>

    <div class="row-fluid">
    </div>

    <div class="row-fluid">
        <div class="span8">
            <div class="card grey">
                <a class="btn btn-primary pull-right">Add Slot &raquo;</a>
                <h2 class="title">Slots</h2>

                <?php
                $name = get_user_relation_data('venue','name',get_user_id());
                query_posts(array( 'post_type' => 'pitches','showposts' => 100));
                while (have_posts()) : the_post();
                    if (get_relation_data('venue','name') == $name) {
                        $pid = get_field('pid');
                        ?>
                        <div class="card">
                            <h3><? the_field('pid'); ?></h3>
                            <?
                            $the_query2 = new WP_Query(array( 'post_type' => 'slots','showposts' => 100));
                            $slotcount = 0;
                            while ($the_query2->have_posts()) : $the_query2->the_post();
                                if (get_any_relation_data('pitch','pid',$the_query2->post->ID) == $pid) {
                                    $slotcount++;
                                    if ($slotcount == 1) {
                                        ?>
                                <table class="table table-bordered table-striped">
                                    <thead>
                                    <tr>
                                        <th>Start</th>
                                        <th>End</th>
                                        <th>Day</th>
                                        <th>Price</th>
                                        <th>Action</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                   <? } ?>
                                <tr>
                                    <td><? the_field('start_time',$the_query2->post->ID); ?></td>
                                    <td><? the_field('end_time',$the_query2->post->ID); ?></td>
                                    <td><? the_field('day',$the_query2->post->ID); ?></td>
                                    <td>&pound;<? the_field('price',$the_query2->post->ID); ?></td>
                                    <td style="text-align:left; white-space: nowrap"><a class="btn btn-small" style="margin-bottom: 5px">Edit &raquo;</a> &nbsp; <a style="margin-bottom: 5px" class="btn btn-small btn-danger">Delete &raquo;</a></td>
                                </tr>
                                    <?
                                }
                            endwhile;
                            if ($slotcount == 0) {echo 'No Slots';} else { ?> </tbody></table><? } ?>
                        </div>
                        <?
                    }
                endwhile;
                ?>

            </div>
        </div>
        <div class="span4">
            <div class="card grey">
                <h2 class="title"></h2>

            </div>
        </div>
    </div>
</div>


<?php get_footer(); ?>